/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import model.util.MySQLProviders;

/**
 *
 * @author Mr.Thanh
 */
public class PhanTrangDAO {
    public static int laySoLuong(String table) {
      String sql = "select count(*) as soluong from "+table;
      int soLuong = -1;
      try {
         MySQLProviders helper = new MySQLProviders();
         helper.open();
         ResultSet rs = helper.executeQuery(sql);
         if (rs.next()) {
            soLuong = rs.getInt("soluong");
         }
         helper.close();
      } catch (SQLException ex) {
         System.out.println(ex.getMessage());
      }
      return soLuong;
   }
    
    public static int tinhSoLuongTrang(String table) {
      int soTrang=1;
      int soLuongSanPhamTrenTrang = ThamSoDAO.laySoLuongTrenTrang();
      int soLuong = laySoLuong(table);
      soTrang = soLuong / soLuongSanPhamTrenTrang;
      if (soLuong % soLuongSanPhamTrenTrang != 0) {
         soTrang++;
      }
      return soTrang;
   }
    
   
}
